package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

public class UdpEchoDictServer extends UdpEchoServer{
    private Map<String,String> dict=new HashMap<String,String>();
    public UdpEchoDictServer(int port) throws SocketException {
        //父类的构造方法是带参数的，所以在子类的构造方法中要先显式调用父类的构造方法，且要写在第一行
        super(port);
        dict.put("hello","你好");
        dict.put("world","世界");
        dict.put("university","大学");
        dict.put("student","学生");
        dict.put("pen","钢笔");
        dict.put("canteen","食堂");
        dict.put("computer","电脑");
        dict.put("notebook","笔记本");
        dict.put("vacation","假期");
        dict.put("money","钱");
    }
    @Override
    public String process(String request){
        return dict.getOrDefault(request,"没找到该单词");
    }

    public static void main(String[] args) throws IOException {
        UdpEchoDictServer server=new UdpEchoDictServer(9090);
        server.start();
    }
}
